const common = require('./webpack.common')
const { merge } = require('webpack-merge')
const { CleanWebpackPlugin } = require('clean-webpack-plugin')
const CopyWebpackPlugin = require('copy-webpack-plugin')
const uglifyjsWebpackPlugin = require('uglifyjs-webpack-plugin')

const option = {

    mode: 'production',
    optimization: {
        usedExports: true, //忽略未引用代码
        concatenateModules: true, //合并模块，尽可能将所有的模块放在同一个方法中
        minimizer: [ //webpack官方建议我们将代码压缩类的插件均放在此处，意为当代码需要压缩打包时才执行这些插件而不是每次打包，使用此处打包后需要自己添加js压缩。
            new OptimizeCssAssetsWebpackPlugin(),
            new uglifyjsWebpackPlugin(), //由于压缩样式文件会自动将压缩方法替换，webpack将不再自动压缩js文件需手动压缩。
        ]
    },
    plugins: [
        new CleanWebpackPlugin(),
        new CopyWebpackPlugin({
            patterns: [
                { from: 'public', to: 'static' }
            ]
        })
    ]
}

const mergeConfig = merge(common)


module.exports = mergeConfig